package com.spring.core.context;

import com.spring.core.bean.AopBean;
import com.spring.core.bean.CustomBean;
import com.spring.core.bean.ComponentBean;
import com.spring.core.constant.BaseConstant;
import com.spring.core.factory.BeanFactory;
import com.spring.core.scan.ComponentScanner;
import com.spring.core.scan.SpringConfigPropertiesScanner;


/**
 * Spring 容器
 *
 * @author Zee
 * @version 1.0
 * @date 2021/10/11
 */
public class AnnotationApplicationContext extends AbstractApplicationContext {

    public AnnotationApplicationContext(Class<?> clazz) {
        super(clazz);
    }

    @Override
    protected void scan() {
        //扫描配置文件
        BeanFactory.getBean(SpringConfigPropertiesScanner.class).doScanner(BaseConstant.PROPERTIES_URL, this);
        //扫描Bean组件
        BeanFactory.getBean(ComponentScanner.class).doScanner(this.getScanPackage(), this);
    }

    @Override
    protected void beanInit() {
        initBefore();
        BeanFactory.getBean(ComponentBean.class).init(this);
        BeanFactory.getBean(CustomBean.class).init(this);
        initAfter();
        BeanFactory.getBean(AopBean.class).init(this);
    }

    private void initBefore() {
          this.getBean("ApplicationContextAware");
    }

    private void initAfter() {

    }

}
